package fr.emn.fil.soc.gr3.views;

import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

import org.apache.log4j.WriterAppender;
import org.apache.log4j.spi.LoggingEvent;

public class ConsoleAppender extends WriterAppender {

	static private JTextArea jTextArea = null;

	static public void setTextArea(JTextArea jTextArea) {
		ConsoleAppender.jTextArea = jTextArea;
	}

	@Override
	public void append(LoggingEvent loggingEvent) {
		final String message = this.layout.format(loggingEvent);

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				if(jTextArea != null)
					jTextArea.append(message);
			}
		});
	}
}
